<?php 
## include required files
/*******************************/
require_once '../model/faqs.php';

/*******************************/
## Create Objects
/*******************************/
$faqObj = new Model_FAQ();
/*******************************/

$faq_id = base64_decode($_GET['id']);

if(isset($_POST['editfaq_btn'])) {
	## apply PHP validation for required filed
	if(trim($_POST['faq_ques']) != '' && trim($_POST['faqans_content']) != '') {
		$submenuArray = array();
		extract($_POST);
		$faqArray['faq_category_id']   = $_POST['faq_cat'];
		$faqArray['faq_question']      = return_post_value($_POST['faq_ques']);
		$faqArray['faq_answer']        = return_post_value($faqans_content);
		$faqObj->editFaqById($faqArray,$faq_id);
		$_SESSION['msg'] = "<div class='success_msg'><span>FAQ edited successfully</span></div>";
		header('location:'.SITE_URL.'/admin/home.php?q=faqs&page='.$_POST['page']);
		exit;
	} else {// php validation else
		$_SESSION['msg'] = '<div class="error_msg"><span>Please enter faq question and answer</span></div>';
	}
	// main if closed
}

## Fetch faq categories
$faqcatArray=$faqObj->getAllFaqsCategoryWithActiveStatus();
$smarty->assign('faqcatArray', $faqcatArray);

if($_GET['id']!=''&& $_GET['action']=='edit') {
	
	$faqArray = $faqObj->getFaqDetailsById($faq_id);
	$smarty->assign('faqArray', $faqArray);
}

## Assign success or error msg to smarty variable and unset session variable
if(trim($_SESSION['msg']) != '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}

## Set active class variable for left menu
$smarty->assign('activeclass', 'faqs');
$smarty->assign('mainmenu', '2');
## Unset all the objects created which are on this page
unset($faqObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'faq/editfaq.tpl');
unset($smarty);
?>